package com.mew.slots.core.game.tjcs.room;

import com.mew.slots.core.common.game.BaseRoom;
import com.mew.slots.core.common.game.vo.BasePlayMsgs;
import com.mew.slots.core.game.tjcs.roller.Controlline;
import com.mew.slots.core.game.tjcs.roller.TjcsIli;

import java.util.ArrayList;

public class TjcsRoom extends BaseRoom {
    public static int _FREE = 12;
    int freeRate;
    public TjcsRoom(int freeRate){
        this.freeRate=freeRate;
        res = new BasePlayMsgs();
        row = 3;
        col = 5;
        _WILD = 11;
        spes = new ArrayList<Integer>(){{
            add(_FREE);
        }};

         rate = new int[][]{
                {0, 0,  5, 10, 100},//0  9
                {0, 0,  5, 15, 100},//1  10
                {0, 0, 10, 15, 100},//2   J
                {0, 0, 10, 15, 100},//3   Q
                {0, 0, 10, 20, 200},//4   K
                {0, 0, 10, 30, 200},//5   A
                {0, 0, 15, 35, 300},//6   福袋
                {0, 0, 20, 50, 300},//7   竹子
                {0, 0, 30, 100,800},//8   玉佩
                {0, 0, 35, 100,800},//9   鲤鱼
                {0, 0, 50, 100,1000},//10 金蟾

                 {0, 0, 0,  0,   0},//11  WILD
                 {0, 0, 0,  0,   0}//12   Scatter
        };

         alllines = new int[][]{
                 {5,6,7,8,9},
                 {0,1,2,3,4},
                 {10,11,12,13,14},
                 {0,6,12,8,4},
                 {10,6,2,8,14},
                 {5,1,2,3,9},
                 {5,11,12,13,9},
                 {0,1,7,13,14},
                 {10,11,7,3,4},
                 {5,11,7,3,9},
                 {5,1,7,13,9},
                 {0,6,7,8,4},
                 {10,6,7,8,14},
                 {0,6,2,8,4},
                 {10,6,12,8,14},
                 {5,6,2,8,9},
                 {5,6,12,8,9},
                 {0,1,12,3,4},
                 {10,11,2,13,14},
                 {0,11,12,13,4},
                 {10,1,2,3,14},
                 {5,11,2,13,9},
                 {5,1,12,3,9},
                 {0,11,2,13,4},
                 {10,1,12,3,14},
                 {10,1,7,13,4},
                 {0,11,7,3,14},
                 {0,11,7,13,4},
                 {10,1,7,3,14},
                 {10,6,2,3,9},
                 {0,6,12,13,9},
                 {0,1,12,13,14},
                 {10,11,2,3,4},
                 {5,1,12,8,14},
                 {5,11,2,8,4},
                 {0,6,2,8,14},
                 {10,6,12,8,4},
                 {5,11,12,3,4},
                 {0,1,7,8,14},
                 {10,11,7,8,4},
                 {10,1,2,3,4},
                 {0,11,12,13,14},
                 {10,11,12,13,4},
                 {0,1,2,3,14},
                 {5,1,7,3,9},
                 {5,11,7,13,9},
                 {0,6,12,13,14},
                 {10,6,2,3,4},
                 {0,6,7,8,9},
                 {10,6,7,8,9}
        };
    }
    @Override
    public int[] getIliEndSlots(){
        if(free){
            return iliXml.getSpeints("mfree");
        }
        return iliXml.getLineints(0,rollerID,in,0);
    }

    @Override
    public void freeBouns(){
        computeFree();
        if(isFree()){
            res.setMultiple(res.getMultiple()*freeRate);
            for (BasePlayMsgs.LineResult line : res.getLines()) {
                for (int uvIdx : line.getUvIdx()) {
                    if(endSlots[uvIdx]==_WILD){
                        res.setFree((byte) 1);
                        res.setFreeNumber(1);
                        return;
                    }
                }
            }
        }
    }

    private void computeFree(){
        int freeNum=fsdb(_FREE);
        if(freeNum>2){
            getRes().setFree((byte) 1);
        }
    }

 /*   @Override
    public int[] control(){
        Controlline controlline=new Controlline();
        switch (controlType) {
            case 1:
                return controlline.bigWin();
            case 2:
                return controlline.free();
            default:
                return controlline.empty();
        }
    }*/

    @Override
    public int[] control(){
        TjcsIli instance = TjcsIli.getInstance();
        switch (controlType) {
            case 1:
                return instance.getSpeints("21-23");
            case 2:
                return instance.getSpeints("free");
            default:
                return instance.getSpeints("0-0");
        }
    }
}
